<?php
ini_set('display_errors', 1); 
ini_set('error_reporting', 'E_error'); 
$wishlist_id=$_REQUEST['wishlist_id'];
require_once '../includes/image_resizer.php';


if(isset($_REQUEST['CategoryKey']))
 {
	    $product_name=$_REQUEST['product_name'];
        $price=$_REQUEST['wishprice'];
        $description=$_REQUEST['description'];
        $wishImage=$_FILES["productImage"]["name"];
	    $wishlist_id=$_REQUEST['wishlist_id'];
		$cat_id=$_REQUEST['wish_cat'];
	
     		
       $sql_addcat="Update tbl_whole_wishlist set product_name='$product_name',price='$price',description='$description',cat_id='".$cat_id."' where wishlist_id=$wishlist_id";
       $rst_addcat=mysql_query($sql_addcat) or die(mysql_error());
       
       $wishId=$wishlist_id;
       $wishImage = $_FILES["productImage"]["name"];
       $imageInfo=pathinfo($wishImage);		
       $wishType = strtolower($imageInfo['extension']);
       if(!empty($wishType)) {						
	       if($wishType=="jpeg" || $wishType=="jpg" || $wishType=="png" || $wishType=="gif") {				
		       $rand=mt_rand();					
		       $path="../wishlist/source/".$rand.$wishId.".".$wishType;					
		       $path_thumb="../wishlist/thumb/".$rand.$wishId."_thumb.".$wishType;					
		       $path_medium="../wishlist/medium/".$rand.$wishId."_medium.".$wishType;
		       
		       //$path1="wishlist/source/".$rand.$wishId.".".$wishType;					
		       $path_thumb1="wishlist/thumb/".$rand.$wishId."_thumb.".$wishType;					
		       $path_medium1="wishlist/medium/".$rand.$wishId."_medium.".$wishType;
		       move_uploaded_file($_FILES["productImage"]["tmp_name"],$path);				  
		       productResize($path, $path_thumb, $path_medium, $wishType);	
		       
		       $sql_updpro="UPDATE tbl_whole_wishlist set 
						product_image='".$path_medium1."',
						product_thumb='".$path_thumb1."'								
						where wishlist_id=$wishId";	
		       $rst_updpro=mysql_query($sql_updpro) or die(mysql_error());
		       if(mysql_affected_rows()>0) { 
			       //unlink($path);
			       $msgEditScat="<div id='suc-msg'> Product updated with image to your wishlist. </div>"; 
		       } else {
			       $msgEditScat="<div id='suc-msg'> Product updated to your wishlist. </div>						
				       <div id='err-msg'> Error in adding product image.</div>";
		       }	
	       }else {
		       $msgEditScat="<div id='suc-msg'> Product updated to your wishlist. </div>						
			       <div id='err-msg'> Error in adding product image. Upload jpg,png and gif formats only.</div>";
	       }	
	}
	else {
	           $msgEditScat="<div id='suc-msg'> Product update to your wishlist. </div>";
	      }
	
	//$msgEditScat="Shipping Service Edited Successfully";
	
 }
 if($wishlist_id==0)
 {
 	$task="Add";
 }
 else
 {
 	$task="Edit";
 }
 
$sqlSelEditSubcategory="select * from tbl_whole_wishlist where wishlist_id=$wishlist_id";
$rstSelEditSubcategory=mysql_query($sqlSelEditSubcategory);
$rowSelEditSubcategory=mysql_fetch_array($rstSelEditSubcategory);
$product_name=$rowSelEditSubcategory['product_name'];
$price=$rowSelEditSubcategory['price'];
$description=$rowSelEditSubcategory['description'];
$product_image=$rowSelEditSubcategory['product_image'];
$product_thumb=$rowSelEditSubcategory['product_thumb'];
 
?>
<table width="100%"  border="1" cellspacing="0" class="container">
  <tr>
    <td width="469" height="25" class="tdHeader">Edit Wishlist<span style="text-align:right; padding-left:350px;"><input type='button' name='addsscat' value='Back' class='button' onClick="window.location='index.php?list_mwishlist'"  /></span></td>
  </tr>
  <tr>
    <td>	
          <form action="" method="post" name="formEditSubCat" id="formEditSubCat" enctype="multipart/form-data">
		  <input type="hidden" name="CategoryKey" id="CategoryKey" value="1">
           <table width="423" border="0" cellspacing="0" align="center">
          <tr>
            <td height="40" colspan="3"><div align="center"><?php echo "<b>".$msgEditScat."</b>"; ?></div></td>
            
          </tr>
		 
		  <tr>
		  	<td colspan="3">&nbsp;</td>
		  </tr>
          <tr>
            <td height="29">&nbsp;</td>
            <td><div align="left">Category </div></td>
            <td>
              <div align="left"><select name="wish_cat" id="wish_cat">
			  <option value="">Select</option>
                <?php
				$sqlWishCat="SELECT * FROM tb1_wanted_category";
				$exeWishCat=mysql_query($sqlWishCat) or die(mysql_error());
				while($arrWishCat=mysql_fetch_array($exeWishCat)) {
				?>
				<option value="<?php echo stripslashes($arrWishCat['wanted_cat_id']); ?>" <?php if($rowSelEditSubcategory['cat_id']==$arrWishCat['wanted_cat_id']) { echo 'selected'; }?>><?php echo stripslashes($arrWishCat['cat_name']); ?></option>
				<?php } ?>
				</select>
              </div></td>
          </tr>
          <tr>
            <td height="29">&nbsp;</td>
            <td><div align="left">Product Name </div></td>
            <td>
              <div align="left">
                <input type="text" name="product_name" id="product_name" value="<?php echo $product_name; ?>">
              </div></td>
          </tr>
	  <tr>
	      <td height="29">&nbsp;</td>
	      <td><div align="left">Wish Price</div></td>
	      <td><div align="left"><input type="text" value="<?=$price?>" name="wishprice" id="wishprice" />
	                            <input type="hidden" value="<?=$wishlist_id?>" name="wishlist_id" id="wishlist_id" />
	      </div></td>
          </tr>
	  <tr>
            <td height="31">&nbsp;</td>
            <td>Description </td>
            <td><textarea name="description" id="description" cols="25" rows="5"><?php echo $description; ?></textarea></td>
          </tr>
	  <tr>
          <td height="31">&nbsp;</td>
          <td valign="top">Product Image</td>
          <td>
	      
	      <img src="../<?=$product_thumb?>" width="100" height="100"><br>
	      <label>
            <input type="file" name="productImage" id="productImage">
          </label></td>
        </tr>
          <tr>
            <td height="65" colspan="3"><div align="center">
                <input name="Submit" type="submit" value="<?php echo $task;?> Service" class="button" onClick="return editwishlist();">
              </div></td>
         </tr>
        </table>
       </form>
     </td>
  </tr>
</table>

